import Demo2.Computer;
import Demo2.IRunning;
import Demo2.KeyBoard;
import Demo2.Mouse;

import java.sql.SQLOutput;
import java.util.Comparator;

/*
 *Description:
 *User:laoHu
 *Created with Intellij IDEA 2025
 *Data:2025.06.17
 *Time:18:40
 */
class Student{
//成员变量
    String name;
    int age;
//构造方法
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
//重写toString方法
    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
//实现年龄比较器，比较器中的类型的Student
class CompareAge implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.age - o2.age;
    }
}
//实现名字比较器，比较器中的类型是Student
class CompareName implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}

public class Main {

    public static void main3(String[] args) {
        Student student1 = new Student("cuihua",18);
        Student student2 = new Student("xiaohai",33);

        //使用年龄比较器
       CompareAge compareAge = new CompareAge();
        System.out.println(compareAge.compare(student1,student2));

        //使用名字比较器
        CompareName compareName =new CompareName();
        System.out.println(compareName.compare(student1,student2));
    }

    public static void main2(String[] args) {
        Student student1 = new Student("lisi",20);
        Student student2 = new Student("lisa",22);

//        //比较年龄//student1指向的对象年龄小于student2指向对象的年龄
//        System.out.println(student1.compareTo(student2));
//        //做差：-2
    }
    public static void main(String[] args) {
        //实例化对象
        Computer computer1 = new Computer();
        //打开电脑
        computer1.powerOn();
        //使用电脑：接入鼠标
        computer1.useComputer(new Mouse());
        //关机
        computer1.powerOff();
        System.out.println("=================");
        //实例化对象
        Computer computer2 = new Computer();
        //打开电脑
        computer2.powerOn();
        //使用电脑：接入键盘
        computer2.useComputer(new KeyBoard());
        //关闭电脑
        computer2.powerOff();
    }
}